# -*- coding: utf-8 -*-
# @Author   : niejiali
# @Time     : 2019/1/21 10:12
# @File     : base.py
# @Software : PyCharm
from flask import request
from wtforms import Form

from app.lib.error_code import ParameterException


class BaseForm(Form):
    def __init__(self):
        data = request.json
        super(BaseForm, self).__init__(data=data)

    def validate_for_api(self):
        valid = super(BaseForm, self).validate()
        if not valid:
            # form errors
            raise ParameterException(msg=self.errors)
        return self